package com.shanks.home.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.shanks.home.R;

public class GridViewAdapter extends BaseAdapter{

	private Context context;	

	private int[] ImageResId = {R.drawable.imgface_1, R.drawable.imgface_2, R.drawable.imgface_3, R.drawable.imgface_4,
			R.drawable.imgface_5, R.drawable.imgface_6, R.drawable.imgface_7, R.drawable.imgface_8,
			R.drawable.imgface_9, R.drawable.imgface_10, R.drawable.imgface_11, R.drawable.imgface_12,
			R.drawable.imgface_13, R.drawable.imgface_14, R.drawable.imgface_15, R.drawable.imgface_16,
			R.drawable.imgface_17, R.drawable.imgface_18, R.drawable.imgface_19, R.drawable.imgface_20};

	public GridViewAdapter(Context c){
		context = c;
	}		

	@Override
	public int getCount() {
		return ImageResId.length;
	}

	@Override
	public Object getItem(int position) {
		return ImageResId[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.headimage_item, null);

			viewHolder = new ViewHolder();
			viewHolder.headImageView = (ImageView)convertView.findViewById(R.id.headimage_item_iv);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Drawable drawable = (Drawable) context.getResources().getDrawable(ImageResId[position]);
		viewHolder.headImageView.setImageDrawable(drawable);
		return convertView;
	}

	private class ViewHolder{
		public ImageView headImageView;
	}
}